
$(document).ready(function() {
    var Main = {
        data() {
            return {
                activeName: 'first'
            };
        },
        created() {

        },
        methods: {
            cellStyle({ row, column, rowIndex, columnIndex }) {
                // 判断单元格内容是否为"正确"
                if (row[column.property] === '正确') {
                    return 'color: green';
                }else if (row[column.property] === '不正确') {
                    return 'color: red';
                }
                return ''; // 默认不设置样式
            },
            handleClick(tab, event) {
                console.log(tab, event);
            },
            // 添加最新开奖信息
            addData() {
                let _this = this;
                var data = {
                    qihao: $("#qihao").val(),
                    kjDate: $("#kjDate").val(),
                    kj:  $("#kj").val(),
                    sj: $("#sj").val(),
                    zj: $("#zj").val()
                }

                $.ajax({
                    url: 'http://localhost:8809/fucai/3d/addData',
                    type: 'POST',
                    contentType: "application/json", // 指定请求体格式为 JSON
                    data: JSON.stringify(data),
                    success: function(response) {
                        console.log("请求成功:", response);
                        if (response > 0){
                            _this.$message({
                                message: '恭喜你，添加成功',
                                type: 'success'
                            });
                        }
                    },
                    error: function(xhr, status, error) {
                        console.log('Request failed:', status, error);
                    }
                });
            },
            // 复制选中数据
            copySelectData(type){
                const selectDatas = $(".select_number_haoma");
                debugger
                let copyStr = '';
                for (let i = 0; i < selectDatas.length; i++){
                    let haoma = $(selectDatas[i]).text();
                    let one = haoma.charAt(0);
                    let two = haoma.charAt(1);
                    let three = haoma.charAt(2);
                    // 当前元素中的形态
                    let thisXingtai = '';

                    if (one == two && two == three){
                        thisXingtai = '豹子';
                    }else if (one == two || two == three || one == three){
                        thisXingtai = '组三';
                    }else {
                        thisXingtai = '组六';
                    }

                    copyStr += haoma + ' ';

                    if (type == 1){         // 单选复制
                        copyStr += '单选1倍';
                    }else if (type == 2){   // 组选复制
                        if (thisXingtai == '组三'){
                            copyStr += '组三1倍';
                        }else if (thisXingtai == '组六'){
                            copyStr += '组六1倍';
                        }else if (thisXingtai == '豹子'){
                            copyStr += '单选1倍';
                        }
                    }
                    copyStr += '\n';
                }
                // 使用Clipboard API复制文本到剪贴板
                navigator.clipboard.writeText(copyStr).then(() => {
                    this.$message({
                        message: '复制成功',
                        type: 'success',
                        duration: 800
                    });
                }).catch(err => {
                    this.$message({
                        message: '复制失败',
                        type: 'success'
                    });
                });
            }
        }
    };

    var Ctor = Vue.extend(Main)
    new Ctor().$mount('#app')


    // 最新一期开机号
    const new_kj = "169";
    // 最新一期试机号
    const new_sj = "";

    $("#kj").val(new_kj);
    $("#sj").val(new_sj);

    //  获取最新数据并填充至页面
    getNewData();

    if (new_kj != ""){
        const new_kj_b = new_kj.substring(0, 1);
        const new_kj_s = new_kj.substring(1, 2);
        const new_kj_g = new_kj.substring(2, 3);
        const new_kj_hezhi = Number(new_kj_b) + Number(new_kj_s) + Number(new_kj_g);
        const new_kj_max = Math.max(new_kj_b, new_kj_s, new_kj_g);
        const new_kj_min = Math.min(new_kj_b, new_kj_s, new_kj_g);
        const new_kj_kuadu = Number(new_kj_max) - Number(new_kj_min);

        $(".new_data_kj").html(new_kj);
        $(".new_data_kj_kuadu").html(new_kj_kuadu);
        $(".new_data_kj_hezhi").html(new_kj_hezhi);
        $(".new_data_kj_hezhi_wei").html(new_kj_hezhi % 10);
    }

    if (new_sj != ""){
        const new_sj_b = new_sj.substring(0, 1);
        const new_sj_s = new_sj.substring(1, 2);
        const new_sj_g = new_sj.substring(2, 3);
        const new_sj_hezhi = Number(new_sj_b) + Number(new_sj_s) + Number(new_sj_g);
        const new_sj_max = Math.max(new_sj_b, new_sj_s, new_sj_g);
        const new_sj_min = Math.min(new_sj_b, new_sj_s, new_sj_g);
        const new_sj_kuadu = Number(new_sj_max) - Number(new_sj_min);

        $(".new_data_sj").html(new_sj);
        $(".new_data_sj_kuadu").html(new_sj_kuadu);
        $(".new_data_sj_hezhi").html(new_sj_hezhi);
        $(".new_data_sj_hezhi_wei").html(new_sj_hezhi % 10);
    }

    // 添加tip监听器
    addTipListener();

});

/**
 * 初始化推荐期号
 */
function initTuijianQihao(defaultQihao){
    $("#tuijian_qihao option").remove();

    const qihaoNian = 2025;
    for (let i = 1; i <= 359; i++){
        let tuijian_qihao = qihaoNian + String(i).padStart(3, '0');
        let option = $("<option value='" + tuijian_qihao + "'>" + tuijian_qihao + "</option>");
        if (tuijian_qihao == defaultQihao){
            option = $("<option value='" + tuijian_qihao + "' selected>" + tuijian_qihao + "</option>");
        }
        $("#tuijian_qihao").append(option);
    }
}

/**
 * 时间加一天
 */
function addOneDay(dateStr) {
    // 提取日期部分（如"2025-09-03"）
    const datePart = dateStr.match(/\d{4}-\d{2}-\d{2}/)[0];

    // 创建日期对象并加一天
    const date = new Date(datePart);
    date.setDate(date.getDate() + 1);

    // 格式化新日期
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');

    return `${year}-${month}-${day}`;
}

/**
 * 根据数据库中数据设置推荐数据
 */
function setTuijianByDb(fucai3dTuijianList){

    // 删除页面数据,重新绘制
    $(".tuijian_data_tr").remove();

    fucai3dTuijianList.forEach(fucai3dTuijian =>{
        let trHtml = '<tr class="tuijian_data_tr">';
        trHtml = trHtml + '<td>' + fucai3dTuijian.tuijianRen + "</td>";
        trHtml = trHtml + '<td colspan="3">';
        trHtml = trHtml + '杀一:<span class="data_tuijian_sha1">';
        trHtml = trHtml + fucai3dTuijian.tuijianSha1;
        trHtml = trHtml + '</span>';
        trHtml = trHtml + ',杀二:<span class="data_tuijian_sha2">';
        trHtml = trHtml + fucai3dTuijian.tuijianSha2;
        trHtml = trHtml + '</span>';
        trHtml = trHtml + ',七码:<span class="data_tuijian_qima">';
        trHtml = trHtml + fucai3dTuijian.tuijianQima;
        trHtml = trHtml + '</span>';
        trHtml = trHtml + '</td>';
        trHtml = trHtml + '</tr>';

        $("#tuijian_sha1_shengyu").before(trHtml);

        if (fucai3dTuijian.tuijianRen == '袁慧贤'){
            let data_tuijian_yuanhuixian_shengyu = "0123456789";
            data_tuijian_yuanhuixian_shengyu = data_tuijian_yuanhuixian_shengyu.replace(fucai3dTuijian.tuijianSha2.charAt(0), "");
            data_tuijian_yuanhuixian_shengyu = data_tuijian_yuanhuixian_shengyu.replace(fucai3dTuijian.tuijianSha2.charAt(1), "");

            $(".data_tuijian_yuanhuixian_shengyu").html(data_tuijian_yuanhuixian_shengyu);
        }
    });
}

/**
 * 填充数据
 * @param data
 */
function fillData(data, isNew){
    if (isNew){
        // 设置添加最新开奖数据的期号
        const newQihaoNian = String(data.qihao).substring(0, 4);
        const newQihao = String(Number(String(data.qihao).substring(4, 7)) + 1).padStart(3, '0');
        let newQihaoAll = newQihaoNian + newQihao;
        $("#qihao").val(newQihaoAll);

        const newKjDate = addOneDay(data.kjDate);
        $("#kjDate").val(newKjDate);

        // 初始化推荐期号
        initTuijianQihao(newQihaoAll);

        // 查询推荐数据,查询完成后填充到页面
        queryTuijianData( newQihaoAll, null);
    }
}

// 选中的位置
var select_weizhi = [];
// 选中的和值路数
var select_hezhiLu = [];
// 选中的和值
var select_hezhi = [];
// 选跨度
var select_kuadu = [];
// 和值加跨度尾
var select_he_kua_wei = [];
// 选中的号码
var select_xuanhao = [];
// 选号方式（1:包含任一,2:精确）
var select_xuanhaofangshi = '';
// 选中的杀号
var select_shahao = [];
// 选中的形态
var select_xingtai = '';

/**
 * 根据和值路数选择号码
 * @param e 当前元素
 * @param weizhi 位置
 * @param hezhiLu 和值路数
 * @param hezhi 和值
 * @param kuadu 跨度
 * @param hekuawei 和值加跨度尾
 * @param xuanhaofangshi 选号方式（renyi:包含任一,jingque:精确）
 * @param hao 选号
 * @param shahao 杀号
 * @param xingtai 形态
 */
function selectHaoma(e, weizhi, hezhiLu, hezhi, kuadu, hekuawei, xuanhaofangshi, hao, shahao, xingtai){
    // 按钮选中状态反选
    $(e).toggleClass("pure-button-primary");

    // 位置选择和反选
    if (weizhi){
        if (select_weizhi.includes(weizhi)){
            select_weizhi.splice(select_weizhi.indexOf(weizhi), 1);
        }else {
            select_weizhi.push(weizhi);
        }
    }
    // 和值路数选择和反选
    if (hezhiLu){
        if (select_hezhiLu.includes(hezhiLu)){
            select_hezhiLu.splice(select_hezhiLu.indexOf(hezhiLu), 1);
        }else {
            select_hezhiLu.push(hezhiLu);
        }
    }
    // 和值选择和反选
    if (hezhi){
        if (select_hezhi.includes(hezhi)){
            select_hezhi.splice(select_hezhi.indexOf(hezhi), 1);
        }else {
            select_hezhi.push(hezhi);
        }
    }
    // 跨度选择和反选
    if (kuadu){
        if (select_kuadu.includes(kuadu)){
            select_kuadu.splice(select_kuadu.indexOf(kuadu), 1);
        }else {
            select_kuadu.push(kuadu);
        }
    }
    // 和值加跨度尾选择和反选
    if (hekuawei){
        if (select_he_kua_wei.includes(hekuawei)){
            select_he_kua_wei.splice(select_he_kua_wei.indexOf(hekuawei), 1);
        }else {
            select_he_kua_wei.push(hekuawei);
        }
    }
    // 选号方式（1:包含任一,2:精确）选择和反选
    if (xuanhaofangshi){
        if (xuanhaofangshi == 'renyi'){
            $(".xuanhaofangshi_jingque").removeClass("pure-button-primary");
        }else if (xuanhaofangshi == 'jingque'){
            $(".xuanhaofangshi_renyi").removeClass("pure-button-primary");
        }
        if (select_xuanhaofangshi == xuanhaofangshi){
            select_xuanhaofangshi = '';
        }else {
            select_xuanhaofangshi = xuanhaofangshi;
        }
    }
    // 号码选择和反选
    if (hao){
        if (select_xuanhao.includes(hao)){
            select_xuanhao.splice(select_xuanhao.indexOf(hao), 1);
        }else {
            select_xuanhao.push(hao);
        }
    }
    // 杀号选择和反选
    if (shahao){
        if (select_shahao.includes(shahao)){
            select_shahao.splice(select_shahao.indexOf(shahao), 1);
        }else {
            select_shahao.push(shahao);
        }
    }
    // 形态选择和反选
    if (xingtai){
        // 按钮选中状态反选
        $(e).siblings().removeClass("pure-button-primary");
        if (select_xingtai == xingtai){
            select_xingtai = '';
        }else {
            select_xingtai = xingtai;
        }
    }

    // 清除选中样式
    $(".hezhi_statistics_table_haoma").removeClass('select_blue_background_color');

    // 判断是否选中
    $(".hezhi_statistics_table_haoma").filter(function(index) {
        // 判断是否选中（true:选中,false:不选中）
        let is = true

        // 没有选中任何条件时,任何号码都不选中
        if (select_weizhi.length == 0 && select_hezhiLu.length == 0 && select_hezhi.length == 0
            && select_kuadu.length == 0 && select_he_kua_wei.length == 0 && select_xuanhao.length == 0
            && select_shahao.length == 0 && select_xingtai == ''
        ){
            is = false;
            return is;
        }

        let haoma = $(this).html();
        if (haoma){
            let one = haoma.charAt(0);
            let two = haoma.charAt(1);
            let three = haoma.charAt(2);
            // 当前元素中的和值
            let thisHeZhi = Number(one) + Number(two) + Number(three);
            // 当前元素中的和值路数
            let thisHeZhiLu = thisHeZhi % 3;
            // 当前元素中的形态
            let thisXingtai = '';
            // 根据当前元素中的最大值和最小值,计算当前元素跨度
            const max = Math.max(Number(one), Number(two),  Number(three));
            const min = Math.min(Number(one), Number(two),  Number(three));
            // 当前元素中的跨度
            let thisKuadu = max - min;
            // 当前元素中的和值加跨度尾
            let thisHeKuaWei = (thisHeZhi + thisKuadu) % 10;

            if (one == two && two == three){
                thisXingtai = '豹子';
            }else if (one == two || two == three || one == three){
                thisXingtai = '组三';
            }else {
                thisXingtai = '组六';
            }

            const lu1 = '0369'.includes(one) ? '0' : '147'.includes(one) ? '1' : '2';
            const lu2 = '0369'.includes(two) ? '0' : '147'.includes(two) ? '1' : '2';
            const lu3 = '0369'.includes(three) ? '0' : '147'.includes(three) ? '1' : '2';

            // 当前号码可组成的位置
            const zuLu = [];
            zuLu.push(String(lu1 + lu2 + lu3));
            zuLu.push(String(lu1 + lu3 + lu2));
            zuLu.push(String(lu2 + lu1 + lu3));
            zuLu.push(String(lu2 + lu3 + lu1));
            zuLu.push(String(lu3 + lu1 + lu2));
            zuLu.push(String(lu3 + lu2 + lu1));

            // 判断当前元素中包含的位置是否是要选择的
            if (select_weizhi && select_weizhi.length > 0){
                let have = false;
                select_weizhi.forEach(lu =>{
                    zuLu.forEach(eleZuLu =>{

                        if (eleZuLu == lu){
                            have = true;
                            return;
                        }
                    })
                });

                if (have){

                }else {
                    is = false;
                    return is;
                }
            }

            // 判断当前元素中和值路数是否是要选择的
            if (select_hezhiLu && select_hezhiLu.length > 0){
                if (!select_hezhiLu.includes(String(thisHeZhiLu))){
                    is = false;
                    return is;
                }
            }

            // 判断当前元素中和值是否是要选择的
            if (select_hezhi && select_hezhi.length > 0){
                if (!select_hezhi.includes(String(thisHeZhi))){
                    is = false;
                    return is;
                }
            }

            // 判断当前元素中的号码是否是要选择的
            if (select_xuanhao && select_xuanhao.length > 0){
                // 精确匹配时,单元格中内容必须包含选中的全部号码
                if (select_xuanhaofangshi == 'jingque'){
                    if (select_xuanhao.length < 2){
                        select_xuanhao.forEach(function (i) {
                            if (!String(haoma).includes(i)){
                                is = false;
                                return is;
                            }
                        })
                    }else {
                        // 将选中号码两两组合
                        let xuanzhongZuhaoArr = [];
                        for (let i = 0; i < select_xuanhao.length; i++){
                            for (let j = i + 1; j < select_xuanhao.length; j++){
                                let xuanzhongZuhao = [];
                                xuanzhongZuhao.push(select_xuanhao[i]);
                                xuanzhongZuhao.push(select_xuanhao[j]);
                                xuanzhongZuhaoArr.push(xuanzhongZuhao);
                            }
                        }
                        let baohan = false;
                        xuanzhongZuhaoArr.forEach(function (xuanzhongZuhao) {
                            if (String(haoma).includes(xuanzhongZuhao[0]) && String(haoma).includes(xuanzhongZuhao[1])){
                                baohan = true;
                                return;
                            }
                        })
                        is = baohan;
                    }
                }else {
                    // 只要单元格中任一号码在选中号码中就选中
                    if (!select_xuanhao.includes(one) && !select_xuanhao.includes(two) && !select_xuanhao.includes(three)){
                        is = false;
                        return is;
                    }
                }
            }

            // 判断当前元素中的形态是否是要选择的
            if (select_xingtai && select_xingtai != '全部'){
                if (thisXingtai != select_xingtai){
                    is = false;
                    return is;
                }
            }

            // 判断当前元素中跨度是否是要选择的
            if (select_kuadu && select_kuadu.length > 0){
                if (!select_kuadu.includes(String(thisKuadu))){
                    is = false;
                    return is;
                }
            }

            // 判断当前元素中"和值加跨度尾"是否是要选择的
            if (select_he_kua_wei && select_he_kua_wei.length > 0){
                if (!select_he_kua_wei.includes(String(thisHeKuaWei))){
                    is = false;
                    return is;
                }
            }

            // 判断当前元素中跨度是否是要选择的
            if (select_shahao && select_shahao.length > 0){
                // 只要单元格中任一号码在杀号中就剔除
                if (select_shahao.includes(one) || select_shahao.includes(two) || select_shahao.includes(three)){
                    is = false;
                    return is;
                }
            }
        }else {
            is = false;
        }
        return is;
    }).addClass("select_blue_background_color");

    // 将选中号码放入选号区
    addSelectData();
}

/**
 * 根据左侧条件筛选数据
 */
function addSelectData(){
    var selectDatas = $(".hezhi_statistics_table_haoma").filter(".select_blue_background_color");
    // 清除原有选中信息
    $(".all_select_number tbody tr").remove();
    for (var i = 0; i < selectDatas.length; i++){
        var haoma = $(selectDatas[i]).text();

        let one = haoma.charAt(0);
        let two = haoma.charAt(1);
        let three = haoma.charAt(2);
        // 当前元素中的和值
        let thisHeZhi = Number(one) + Number(two) + Number(three);
        // 当前元素中的和值路数
        let thisHeZhiLu = thisHeZhi % 3;
        // 当前元素中的形态
        let thisXingtai = '';
        // 根据当前元素中的最大值和最小值,计算当前元素跨度
        const max = Math.max(Number(one), Number(two),  Number(three));
        const min = Math.min(Number(one), Number(two),  Number(three));
        // 当前元素中的跨度
        let thisKuadu = max - min;
        // 当前元素中的和值加跨度尾
        let thisHeKuaWei = (thisHeZhi + thisKuadu) % 10;

        if (one == two && two == three){
            thisXingtai = '豹子';
        }else if (one == two || two == three || one == three){
            thisXingtai = '组三';
        }else {
            thisXingtai = '组六';
        }

        var tr = "<tr>";
        tr += '<td class="select_number_haoma">' + haoma + '</td>';
        tr += '<td class="select_number_hezhi">' + thisHeZhi + '</td>';
        tr += '<td class="select_number_kuadu">' + thisKuadu + '</td>';
        tr += '<td class="select_number_hejiakua">' + thisHeKuaWei + '</td>';
        tr += '<td class="select_number_xingtai">' + thisXingtai + '</td>';
        tr += "</tr>";
        $(".all_select_number tbody").append(tr);
    }

    $("#selectDataCount").text(selectDatas.length);
}

// 选中的位置
var select_right_weizhi = [];
// 选中的和值路数
var select_right_hezhiLu = [];
// 选中的和值
var select_right_hezhi = [];
// 选中的跨度
var select_right_kuadu = [];
// 和值加跨度尾
var select_right_he_kua_wei = [];
// 选号方式（1:包含任一,2:精确）
var select_right_xuanhaofangshi = '';
// 选中的号码
var select_right_xuanhao = [];
// 选中的杀号
var select_right_shahao = [];
// 选中的形态
var select_right_xingtai = '';

/**
 * 根据和值路数选择号码-右侧
 * @param e 当前元素
 * @param weizhi 位置
 * @param hezhiLu 和值路数
 * @param hezhi 和值
 * @param kuadu 跨度
 * @param hekuawei 和值加跨度尾
 * @param xuanhaofangshi 选号方式（renyi:包含任一,jingque:精确）
 * @param hao 选号
 * @param shahao 杀号
 * @param xingtai 形态
 */
function selectHaomaRight(e, weizhi, hezhiLu, hezhi, kuadu, hekuawei, xuanhaofangshi, hao, shahao, xingtai){
    // 按钮选中状态反选
    $(e).toggleClass("pure-button-primary");

    // 位置选择和反选
    if (weizhi){
        if (select_right_weizhi.includes(weizhi)){
            select_right_weizhi.splice(select_right_weizhi.indexOf(weizhi), 1);
        }else {
            select_right_weizhi.push(weizhi);
        }
    }
    // 和值路数选择和反选
    if (hezhiLu){
        if (select_right_hezhiLu.includes(hezhiLu)){
            select_right_hezhiLu.splice(select_right_hezhiLu.indexOf(hezhiLu), 1);
        }else {
            select_right_hezhiLu.push(hezhiLu);
        }
    }
    // 和值选择和反选
    if (hezhi){
        if (select_right_hezhi.includes(hezhi)){
            select_right_hezhi.splice(select_right_hezhi.indexOf(hezhi), 1);
        }else {
            select_right_hezhi.push(hezhi);
        }
    }
    // 跨度选择和反选
    if (kuadu){
        if (select_right_kuadu.includes(kuadu)){
            select_right_kuadu.splice(select_kuadu.indexOf(kuadu), 1);
        }else {
            select_right_kuadu.push(kuadu);
        }
    }
    // 和值加跨度尾选择和反选
    if (hekuawei){
        if (select_right_he_kua_wei.includes(hekuawei)){
            select_right_he_kua_wei.splice(select_right_he_kua_wei.indexOf(hekuawei), 1);
        }else {
            select_right_he_kua_wei.push(hekuawei);
        }
    }
    // 选号方式（renyi:包含任一,jingque:精确）选择和反选
    if (xuanhaofangshi){
        if (xuanhaofangshi == 'renyi'){
            $(".xuanhaofangshi_jingque").removeClass("pure-button-primary");
        }else if (xuanhaofangshi == 'jingque'){
            $(".xuanhaofangshi_renyi").removeClass("pure-button-primary");
        }
        if (select_right_xuanhaofangshi == xuanhaofangshi){
            select_right_xuanhaofangshi = '';
        }else {
            select_right_xuanhaofangshi = xuanhaofangshi;
        }
    }
    // 号码选择和反选
    if (hao){
        if (select_right_xuanhao.includes(hao)){
            select_right_xuanhao.splice(select_right_xuanhao.indexOf(hao), 1);
        }else {
            select_right_xuanhao.push(hao);
        }
    }

    // 形态选择和反选
    if (xingtai){
        // 按钮选中状态反选
        $(e).siblings().removeClass("pure-button-primary");
        if (select_right_xingtai == xingtai){
            select_right_xingtai = '';
        }else {
            select_right_xingtai = xingtai;
        }
    }

    // 杀号选择和反选
    if (shahao){
        if (select_right_shahao.includes(shahao)){
            select_right_shahao.splice(select_right_shahao.indexOf(shahao), 1);
        }else {
            select_right_shahao.push(shahao);
        }
    }

    // 清除选中样式
    $(".shunzi_hekuaxiangdeng_table_haoma").removeClass('select_blue_background_color');

    // 判断是否选中
    $(".shunzi_hekuaxiangdeng_table_haoma").filter(function(index) {
        // 判断是否选中（true:选中,false:不选中）
        let is = true

        // 没有选中任何条件时,任何号码都不选中
        if (select_right_weizhi.length == 0 && select_right_hezhiLu.length == 0 && select_right_hezhi.length == 0
            && select_right_kuadu.length == 0 && select_right_he_kua_wei.length == 0 && select_right_xuanhao.length == 0
            && select_right_shahao.length == 0 && select_right_xingtai == ''
        ){
            is = false;
            return is;
        }

        let haoma = $(this).html();
        if (haoma){
            let one = haoma.charAt(0);
            let two = haoma.charAt(1);
            let three = haoma.charAt(2);
            // 当前元素中的和值
            let thisHeZhi = Number(one) + Number(two) + Number(three);
            // 当前元素中的和值路数
            let thisHeZhiLu = thisHeZhi % 3;
            // 当前元素中的形态
            let thisXingtai = '';
            // 根据当前元素中的最大值和最小值,计算当前元素跨度
            const max = Math.max(Number(one), Number(two),  Number(three));
            const min = Math.min(Number(one), Number(two),  Number(three));
            let thisKuadu = max - min;
            // 当前元素中的和值加跨度尾
            let thisHeKuaWei = (thisHeZhi + thisKuadu) % 10;

            if (one == two && two == three){
                thisXingtai = '豹子';
            }else if (one == two || two == three || one == three){
                thisXingtai = '组三';
            }else {
                thisXingtai = '组六';
            }

            const lu1 = '0369'.includes(one) ? '0' : '147'.includes(one) ? '1' : '2';
            const lu2 = '0369'.includes(two) ? '0' : '147'.includes(two) ? '1' : '2';
            const lu3 = '0369'.includes(three) ? '0' : '147'.includes(three) ? '1' : '2';

            // 当前号码可组成的位置
            const zuLu = [];
            zuLu.push(String(lu1 + lu2 + lu3));
            zuLu.push(String(lu1 + lu3 + lu2));
            zuLu.push(String(lu2 + lu1 + lu3));
            zuLu.push(String(lu2 + lu3 + lu1));
            zuLu.push(String(lu3 + lu1 + lu2));
            zuLu.push(String(lu3 + lu2 + lu1));

            // 判断当前元素中包含的位置是否是要选择的
            if (select_right_weizhi && select_right_weizhi.length > 0){
                let have = false;
                select_right_weizhi.forEach(lu =>{
                    zuLu.forEach(eleZuLu =>{

                        if (eleZuLu == lu){
                            have = true;
                            return;
                        }
                    })
                });

                if (have){

                }else {
                    is = false;
                    return is;
                }
            }

            // 判断当前元素中和值路数是否是要选择的
            if (select_right_hezhiLu && select_right_hezhiLu.length > 0){
                if (!select_right_hezhiLu.includes(String(thisHeZhiLu))){
                    is = false;
                    return is;
                }
            }

            // 判断当前元素中和值是否是要选择的
            if (select_right_hezhi && select_right_hezhi.length > 0){
                if (!select_right_hezhi.includes(String(thisHeZhi))){
                    is = false;
                    return is;
                }
            }
            // 判断当前元素中跨度是否是要选择的
            if (select_right_kuadu && select_right_kuadu.length > 0){
                if (!select_right_kuadu.includes(String(thisKuadu))){
                    is = false;
                    return is;
                }
            }
            // 判断当前元素中"和值加跨度尾"是否是要选择的
            if (select_right_he_kua_wei && select_right_he_kua_wei.length > 0){
                if (!select_right_he_kua_wei.includes(String(thisHeKuaWei))){
                    is = false;
                    return is;
                }
            }
            // 判断当前元素中的号码是否是要选择的
            if (select_right_xuanhao && select_right_xuanhao.length > 0){
                // 2:精确匹配时,单元格中内容必须包含选中的全部号码
                if (select_right_xuanhaofangshi == 'jingque'){
                    if (select_right_xuanhao.length < 2){
                        select_right_xuanhao.forEach(function (i) {
                            if (!String(haoma).includes(i)){
                                is = false;
                                return is;
                            }
                        })
                    }else {
                        let xuanzhongZuhaoArr = [];
                        for (let i = 0; i < select_right_xuanhao.length; i++){
                            for (let j = i + 1; j < select_right_xuanhao.length; j++){
                                let xuanzhongZuhao = [];
                                xuanzhongZuhao.push(select_right_xuanhao[i]);
                                xuanzhongZuhao.push(select_right_xuanhao[j]);
                                xuanzhongZuhaoArr.push(xuanzhongZuhao);
                            }
                        }
                        let baohan = false;
                        xuanzhongZuhaoArr.forEach(function (xuanzhongZuhao) {
                            if (String(haoma).includes(xuanzhongZuhao[0]) && String(haoma).includes(xuanzhongZuhao[1])){
                                baohan = true;
                                return;
                            }
                        })
                        is = baohan;
                    }
                }else {
                    // 只要单元格中任一号码在选中号码中就选中
                    if (!select_right_xuanhao.includes(one) && !select_right_xuanhao.includes(two) && !select_right_xuanhao.includes(three)){
                        is = false;
                        return is;
                    }
                }
            }
            // 判断当前元素中的形态是否是要选择的
            if (select_right_xingtai && select_right_xingtai != '全部'){
                if (thisXingtai != select_right_xingtai){
                    is = false;
                    return is;
                }
            }
            // 判断当前元素中是否有选择的杀号
            if (select_right_shahao && select_right_shahao.length > 0){
                // 只要单元格中任一号码在杀号中就剔除
                if (select_right_shahao.includes(one) || select_right_shahao.includes(two) || select_right_shahao.includes(three)){
                    is = false;
                    return is;
                }
            }
        }else {
            is = false;
        }
        return is;
    }).addClass("select_blue_background_color");
}



/**
 * 选择、反选和值
 * @param e
 */
function selectHezhi(e){
    $(e).toggleClass("select_blue_background_color");
}

/**
 * 填充往期中奖号路数占比统计
 */
function fillZjLuStatisticsWangqi(data){
    $("#zjLuStatistics_wangqi tbody tr").remove();
    $(".zjLuStatistics_wangqi_qihao").html($(".data_qihao").html());
    if (data && data.length > 0){
        for (let i = 0; i < data.length; i++) {
            const element = data[i];
            $("#zjLuStatistics_wangqi tbody").append("<tr>" +
                "<td>" + element.baiqiZjLu + "</td>" +
                "<td>" + element.baiqiZjLuQuantity + "</td>" +
                "</tr>");
        }
    }
}

/**
 * 填充最新中奖号路数占比统计
 */
function fillZjLuStatistics(data){
    $("#zjLuStatistics tbody tr").remove();
    if (data && data.length > 0){
        for (let i = 0; i < data.length; i++) {
            const element = data[i];
            $("#zjLuStatistics tbody").append("<tr>" +
                "<td>" + element.baiqiZjLu + "</td>" +
                "<td>" + element.baiqiZjLuQuantity + "</td>" +
                "</tr>");
        }
    }
}

/**
 * 清空已选择的路号
 */
function clearSelectLuHaoma(){
    $(".hezhi_statistics_table_haoma_red").removeClass("hezhi_statistics_table_haoma_red");
}

/**
 * 根据选择路号选中号码
 * @param e
 * @param lu
 */
function selectLuHaoma(e, lu){
    // 添加选中样式
    $(e).toggleClass("pure-button-primary");
    // 按钮选中状态反选
    $(e).siblings().removeClass("pure-button-primary");

    let tableHaomas = $(".hezhi_statistics_table_haoma");
    for (let i = 0; i < tableHaomas.length; i++) {
        const element = tableHaomas[i];
        const eleLu = $(element).text();
        const c1 = eleLu.charAt(0);
        const c2 = eleLu.charAt(1);
        const c3 = eleLu.charAt(2);

        const lu1 = '0369'.includes(c1) ? '0' : '147'.includes(c1) ? '1' : '2';
        const lu2 = '0369'.includes(c2) ? '0' : '147'.includes(c2) ? '1' : '2';
        const lu3 = '0369'.includes(c3) ? '0' : '147'.includes(c3) ? '1' : '2';

        const zuLu = [];
        zuLu.push(String(lu1 + lu2 + lu3));
        zuLu.push(String(lu1 + lu3 + lu2));
        zuLu.push(String(lu2 + lu1 + lu3));
        zuLu.push(String(lu2 + lu3 + lu1));
        zuLu.push(String(lu3 + lu1 + lu2));
        zuLu.push(String(lu3 + lu2 + lu1));

        let have = false;
        zuLu.forEach(eleZuLu =>{
            if (eleZuLu == lu){
                have = true;
                return;
            }
        })

        if (have){
            $(element).addClass("hezhi_statistics_table_haoma_red");
        }else {
            $(element).removeClass("hezhi_statistics_table_haoma_red");
        }
    }
}


/**
 * 查询推荐数据
 */
function queryTuijianData(tuijianQihao, tuijianRen){
    var data = {
        tuijianQihao: tuijianQihao,
        tuijianRen: null
    }
    $.ajax({
        url: 'http://localhost:8809/fucai/3d/tuijian/queryTuijianData',
        type: 'POST',
        contentType: "application/json", // 指定请求体格式为 JSON
        data: JSON.stringify(data),
        success: function(response) {
            console.log("请求成功:", response);
            // 根据数据库中数据设置推荐数据
            setTuijianByDb(response);
        },
        error: function(xhr, status, error) {
            console.log('Request failed:', status, error);
        }
    });
}


/**
 * 获取最新一期数据
 */
function getNewData(){
    $.ajax({
        url: 'http://localhost:8809/fucai/3d/getNewData',
        type: 'GET',
        success: function(response) {
            console.log("请求成功:", response);
            fillData(response, true);
        },
        error: function(xhr, status, error) {
            console.log('Request failed:', status, error);
        }
    });
}

/**
 * TOP提示监听器
 */
function addTipListener(){
    // 创建 tooltip 元素
    const $tooltip = $('<div class="jquery-tooltip"></div>').appendTo('body');

    // 鼠标悬停事件
    $('.tooltip-trigger').on({
        mouseenter: function(e) {
            const tooltipText = $(this).attr('data-tooltip');
            if (!tooltipText) return;

            $tooltip.text(tooltipText);

            // 延迟显示
            setTimeout(() => {
                $tooltip.css({ display: 'block' });
                updateTooltipPosition(e);
                $tooltip.css({ opacity: '1', transform: 'translateY(0)' });
            }, 200);
        },

        mouseleave: function() {
            $tooltip.css({ opacity: '0', transform: 'translateY(5px)' });
            setTimeout(() => {
                $tooltip.css({ display: 'none' });
            }, 200);
        },

        mousemove: function(e) {
            updateTooltipPosition(e);
        }
    });

    // 更新 tooltip 位置
    function updateTooltipPosition(e) {
        const tooltipWidth = $tooltip.outerWidth();
        const tooltipHeight = $tooltip.outerHeight();
        const windowWidth = $(window).width();
        const windowHeight = $(window).height();

        // 默认位置：鼠标右下方
        let left = e.pageX + 15;
        let top = e.pageY + 15;

        // 防止超出窗口右侧
        if (left + tooltipWidth > windowWidth) {
            left = e.pageX - tooltipWidth - 15;
        }

        // 防止超出窗口底部
        if (top + tooltipHeight > windowHeight) {
            top = e.pageY - tooltipHeight - 15;
        }

        // 防止超出窗口左侧
        if (left < 0) {
            left = 10;
        }

        // 防止超出窗口顶部
        if (top < 0) {
            top = 10;
        }

        $tooltip.css({ left: left + 'px', top: top + 'px' });
    }
}



